

package tables

import (
	"fmt"
	"game/game-design/loader"
	"strings"
	ministruct "sanguo/sanguo-design/src/ministruct"
)


var SkillLevelTable *SkillLevelTableStruct = &SkillLevelTableStruct{}

type SkillLevelTableStruct struct {
	loader.DesignTable[SkillLevelCfg]
	
	skillIdLevelIndex map[string]*SkillLevelCfg
	
	
	
}

func (t *SkillLevelTableStruct) FileName() string {
	return "J技能_技能等级"
}

// 从索引中获取对象，获取不到会抛异常
func (t *SkillLevelTableStruct) GetInSkillIdLevelIndex(
	skillId int32, level int32,
) *SkillLevelCfg {
	key :=
		fmt.Sprint(skillId)+ fmt.Sprint(level)
	
	cfg, ok := t.skillIdLevelIndex[key]
	if !ok {
		panic("SkillLevelTable when GetInSkillIdLevelIndex use key not found " + key)
	}
	return cfg
}

// 从索引中查找对象，获取不到会返回null
func (t *SkillLevelTableStruct) FindInSkillIdLevelIndex(
	skillId int32, level int32,
) (*SkillLevelCfg, bool) {
	key :=
		fmt.Sprint(skillId)+ fmt.Sprint(level)
	
	cfg, ok := t.skillIdLevelIndex[key]
	return cfg, ok
}

// 加载skillIdLevelIndex索引
func (t *SkillLevelTableStruct) loadSkillIdLevelIndex() {
	skillIdLevelIndex := make(map[string]*SkillLevelCfg)
	for _, v := range t.All() {
		keys := []string {
			fmt.Sprint(v.skillId),
			fmt.Sprint(v.level),
		}
		key := strings.Join(keys, "_")
		_, exist := skillIdLevelIndex[key]
		if exist {
			fmt.Println(t.FileName(), " found duplicate key ", key, " in index ", "skillIdLevelIndex")
			continue
		}
		skillIdLevelIndex[key] = v
	}
	t.skillIdLevelIndex = skillIdLevelIndex
}



func (t *SkillLevelTableStruct) LoadAutoGenerate() {
	//加载索引
	t.loadSkillIdLevelIndex()

	
}



type SkillLevelCfg struct {
	idx int32 //序号
	skillId int32 //技能ID
	level int32 //技能等级
	initRound int32 //初始释放回合
	cdRound int32 //冷却回合数
	logicId int32 //技能逻辑ID
	pasLogicId []int32 //被动逻辑ID
}
// 序号
func (c *SkillLevelCfg) GetIdx() int32 {
	return c.idx
}
// 技能ID
func (c *SkillLevelCfg) GetSkillId() int32 {
	return c.skillId
}
// 技能等级
func (c *SkillLevelCfg) GetLevel() int32 {
	return c.level
}
// 初始释放回合
func (c *SkillLevelCfg) GetInitRound() int32 {
	return c.initRound
}
// 冷却回合数
func (c *SkillLevelCfg) GetCdRound() int32 {
	return c.cdRound
}
// 技能逻辑ID
func (c *SkillLevelCfg) GetLogicId() int32 {
	return c.logicId
}
// 被动逻辑ID
func (c *SkillLevelCfg) GetPasLogicId() []int32 {
	return c.pasLogicId
}

func SkillLevelTableStructNoUse() {
	fmt.Println(ministruct.Cost{})
}
